package com.example.myworkers.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.myworkers.model.Goods;
import com.example.myworkers.model.Record;
import com.example.myworkers.service.RecordService;
import com.example.myworkers.dao.RecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 门硕然
* @description 针对表【record】的数据库操作Service实现
* @createDate 2023-10-27 10:00:22
*/
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record>
    implements RecordService{

    @Autowired
    private RecordMapper recordMapper;

    @Override
    public int insertRecord(Record record) {
        int value=0;
        //id不为0
        if(record.getRecordid()>=0)
        {
            //不存在相同id则添加
            if(recordMapper.selectOneByRecordid(record.getRecordid())==null){
                value=recordMapper.insertSelective(record);
            }
        }else {
            value=-1;
        }
        return value;
    }

    @Override
    public Record selectRecord(int id) {
        Record record1=new Record();
        if (id!=0){
            record1=recordMapper.selectOneByRecordid(id);
        }
        return record1;

    }

    @Override
    public int updateRecord(Record record) {
        int value=0;
        //主键不为0
        if(record.getRecordid()!=0) {
            //主键信息必须存在
            if(recordMapper.selectOneByRecordid(record.getRecordid())!=null){
                value=recordMapper.updateSelective(record);
            }
        }
        return value;

    }

    @Override
    public int deleteRecord(int id) {

        int value=0;
        //id不为0
        if(id!=0){
            value=recordMapper.delByRecordid(id);
        }
        return value;
    }
}




